<template>
	<view>
		<button type="primary"  open-type="getUserInfo" @getuserinfo="getUserInfo">登陆</button>
		<button type="primary" @click="login">get code</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			};
		},
		methods: {
			getUserInfo (e) {
				console.log(e)
// 				uni.getUserInfo({
// 					provider: 'weixin',
// 					success: function (infoRes) {
// 						console.log('用户昵称为：' + infoRes.userInfo.nickName);
// 					}
// 				});
			},
			login () {
				uni.getProvider({
					service: 'oauth',
					success: (res) => {
						if (~res.provider.indexOf('weixin')) {
							uni.login({
								provider: 'weixin',
								success: function (loginRes) {
									console.log(JSON.stringify(loginRes))
									// 获取用户信息 这个方式获取到的和 button 获取的其中的detail里面的数据一样
									uni.getUserInfo({
										provider: 'weixin',
										success: function (infoRes) {
											console.log(infoRes)
											// console.log('用户昵称为：' + infoRes.userInfo.nickName);
										}
									});
								}
							});
						}
					},
					fail: (rej) => {
						console.log(rej);
					}
				})
			}
		}
	}
</script>

<style lang="scss">

</style>
